using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson10work 
{
    static private Lesson10work instance=new Lesson10work();

    static public Lesson10work Instance => instance;

    private Dictionary<string, Dictionary<string, Sprite>> dic=new Dictionary<string, Dictionary<string, Sprite>>();



    public Sprite GetSprite(string tujiName,string tupianName)
    {
        if (dic.ContainsKey(tujiName))
        {
            Debug.Log("1");
            if (dic[tujiName].ContainsKey(tupianName))
            {
                Debug.Log("2");

                return dic[tujiName][tupianName];
            
            }
        }
        else
        {
            Debug.Log("3");

            Dictionary<string, Sprite> sdic=new Dictionary<string, Sprite>();
            Sprite[] s = Resources.LoadAll<Sprite>(tujiName);
            for (int i = 0; i < s.Length; i++)
            {
                sdic.Add(s[i].name, s[i]);
            }
            dic.Add(tujiName, sdic);
            if(sdic.ContainsKey(tupianName))
                return sdic[tupianName];
        }
        Debug.Log("4");

        return null;

    }

}
